home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / comm / bbs / s342q16.lha / logedit.c < prev    next >
C/C++ Source or Header  |  1996-09-04  |  11KB  |  404 lines

  1. /*
  2. *                               Logedit.c
  3. *
  4. * Log editor for Citadel-86, V 2.x.
  5. */
  6. /*
  7. *                               history
  8. *
  9. * 89Apr16 HAW  New visual support for PC Clones.  (non-portable)
  10. * 87Oct11 HAW  V3 update.
  11. * 85Nov16 HAW  Modified for MS-DOS libraries.
  12. * 85Aug10 HAW  Created.
  13. */
  14. #include "ctdl.h"    /* header file  */
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include <math.h>
  19. #include <ctype.h>
  20. #include <time.h>
  21. #include <proto/exec.h>
  22. #include <dos/dos.h>
  23. #include <pragmas/dos_pragmas.h>
  24. #include "exec/memory.h"
  25. #include "exec/ports.h"
  26. #include "exec/exec.h"
  27. /*
  28. *                               Contents
  29. *
  30. *       crashout()              irrecoverable error
  31. *       getUNumber()            Gets number from console
  32. *       getUtilString()         Gets string from console
  33. *       logSum()                Sums up the log for logTab
  34. *       main()                  Main controller
  35. */
  36. char NoShow = FALSE;
  37. extern CONFIG    cfg;
  38. extern SListBase MailForward;
  39. extern LogTable *logTab;        /* RAM index of pippuls */
  40. extern logBuffer logBuf;        /* Pippul buffer        */
  41. extern FILE     *logfl;       /* log file descriptor    */
  42. extern int      thisLog;
  43. void getUtilString(char *prompt, char *buf, int lim);
  44. void logSum(void);
  45. void crashout ( char *str );
  46. void handleEditing ( void );
  47. int getUNumber ( char *prompt , unsigned bottom , unsigned top );
  48. void getUtilString ( char *prompt , char *buf , int lim );
  49. int logSort ( LogTable *s1 , LogTable *s2 );
  50. int main ( int argc , char **argv );
  51. void showlog ( void );
  52. void Display_Flag (short,short, char *);
  53.  
  54. /*
  55. * crashout()
  56. *
  57. * This handles an irrecoverable error.
  58. */
  59. void crashout(str)
  60. char *str;
  61.   {
  62.   printf(str);
  63.   exit(10);
  64.  
  65.   }
  66. /*
  67. * handleEditing()
  68. *
  69. * This handles editing accounts in a very primitive manner.
  70. */
  71. void handleEditing()
  72.   {
  73.   char c;
  74.   char mess[40];
  75.   int account;
  76.   label NewName;
  77.   logBuffer lBuf;
  78.   ForwardMail *data;
  79.   initLogBuf(&lBuf);
  80.   sPrintf(mess, "Which account (%d to quit): ", cfg.MAXLOGTAB);
  81.   account = getUNumber(mess, 0, cfg.MAXLOGTAB);
  82.   getLog(&logBuf, account);
  83.   while (account != cfg.MAXLOGTAB)
  84.     {
  85.     showlog();
  86.     printf("LogEdit Menu\n");
  87.     printf("A - toggle Active Acct   \t S - toggle Aide Status\n");
  88.     printf("E - toggle Expert mode   \t N - toggle Net Privileges\n");
  89.     printf("D - toggle Door Privs    \t L - toggle Download Privileges\n");
  90.     printf("B - toggle Permanent Acct\t F - toggle Floor mode\n");
  91.     printf("T - toggle Twit Status   \t R - toggle Ruggie Status\n");
  92.     printf("C - change user name     \n");
  93.     printf("W - change column width  \t G - Go to New account\n");
  94.     printf("J - change LD Net Credit \t Q - Quit\n");
  95.     c = getchar();
  96.     while( getchar() != '\n');
  97.     switch( c )
  98.       {
  99.       case 'j':     /* Net Credit */
  100.       case 'J':
  101.         sPrintf(mess, "Currently %d credits, Enter New:", logBuf.credit);
  102.         logBuf.credit = (int) getUNumber(mess,1,1000);
  103.         putLog(&logBuf, account);
  104.         break;
  105.       case 'w':
  106.       case 'W':
  107.         sprintf(mess,"Enter new column width(40-80):");
  108.         logBuf.lbwidth = getUNumber(mess,40,80);
  109.         putLog(&logBuf, account);
  110.         break;
  111.       case 'g':
  112.       case 'G': /* go to next account */
  113.         sPrintf(mess, "Which account (%d to quit): ", cfg.MAXLOGTAB);
  114.         account = getUNumber(mess, 0, cfg.MAXLOGTAB);
  115.         getLog(&logBuf, account);
  116.         break;
  117.       case 'a':
  118.       case 'A': /* activate an account */
  119.       if (logBuf.lbflags.L_INUSE != 1)
  120.         {
  121.         logBuf.lbflags.L_INUSE = 1;
  122.  
  123.         }
  124.       else
  125.         {
  126.         logBuf.lbflags.L_INUSE = 0;
  127.         if (SearchList(&MailForward, logBuf.lbname) != NULL)
  128.           {
  129.           KillData(&MailForward, logBuf.lbname);
  130.           UpdateForwarding();
  131.  
  132.           };
  133.  
  134.         };
  135.       putLog(&logBuf, account);
  136.       break;
  137.       case 'q' :
  138.       case 'Q' :  /* Quit */
  139.       return;
  140.       break;
  141.       case 'C' :  /* Change a User's name */
  142.       case 'c' :
  143.       getUtilString("new name", NewName, NAMESIZE);
  144.       if (strLen(NewName) != 0)
  145.         {
  146.         if (findPerson(NewName, &lBuf) != ERROR)
  147.           {
  148.           printf("%s already in use.\n", NewName);
  149.  
  150.           }
  151.         else
  152.           {
  153.           if ((data = SearchList(&MailForward,logBuf.lbname)) != NULL)
  154.             {
  155.             data->UserName = strdup(NewName);
  156.             KillData(&MailForward, logBuf.lbname);
  157.             UpdateForwarding();
  158.  
  159.             };
  160.           strCpy(logBuf.lbname, NewName);
  161.           putLog(&logBuf, account);
  162.  
  163.           };
  164.  
  165.         }
  166.       else printf("No name entered, aborted change\n");
  167.       break;
  168.       case 'S' :
  169.       case 's' :
  170.       logBuf.lbflags.AIDE =  (logBuf.lbflags.AIDE) ? 0 : 1;
  171.       putLog(&logBuf, account);
  172.       break;
  173.       case 'E' :
  174.       case 'e' :
  175.       logBuf.lbflags.EXPERT   = logBuf.lbflags.EXPERT ? 0 : 1;
  176.       putLog(&logBuf, account);
  177.       break;
  178.       case 'N' :
  179.       case 'n' :
  180.       logBuf.lbflags.NET_PRIVS= logBuf.lbflags.NET_PRIVS ? 0 : 1;
  181.       putLog(&logBuf, account);
  182.       break;
  183.       case 'D' :
  184.       case 'd' :
  185.       logBuf.lbflags.DOOR_PRIVS = logBuf.lbflags.DOOR_PRIVS ? 0 : 1;
  186.       putLog(&logBuf, account);
  187.       break;
  188.       case 'L' :
  189.       case 'l' :
  190.       logBuf.lbflags.DL_PRIVS = logBuf.lbflags.DL_PRIVS ? 0 : 1;
  191.       putLog(&logBuf, account);
  192.       break;
  193.       case 'B' :
  194.       case 'b' :
  195.       logBuf.lbflags.PERMANENT= logBuf.lbflags.PERMANENT ? 0 : 1;
  196.       putLog(&logBuf, account);
  197.       break;
  198.       case 'F' :
  199.       case 'f' :
  200.       logBuf.lbflags.FLOORS   = logBuf.lbflags.FLOORS ? 0 : 1;
  201.       putLog(&logBuf, account);
  202.       break;
  203.       case 'T' :
  204.       case 't' :
  205.       logBuf.lbflags.TWIT     = logBuf.lbflags.TWIT   ? 0 : 1;
  206.       putLog(&logBuf, account);
  207.       break;
  208.       case 'R' :
  209.       case 'r' :
  210.       logBuf.lbflags.RUGGIE   = logBuf.lbflags.RUGGIE ? 0 : 1;
  211.       putLog(&logBuf, account);
  212.       break;
  213.       Default:  printf("Invalid function Choice\n");
  214.  
  215.       };
  216.  
  217.     };
  218.   /* Loop until User enters Quit */
  219.  
  220.   }
  221. /*
  222. * getUNumber()
  223. *
  224. * This prompts for a number in (bottom, top) range.
  225. */
  226. int getUNumber(prompt, bottom, top)
  227. char   *prompt;
  228. unsigned bottom;
  229. unsigned top;
  230.   {
  231.   unsigned try;
  232.   char numstring[NAMESIZE];
  233.   do
  234.     {
  235.     getUtilString(prompt, numstring, NAMESIZE);
  236.     try     = atoi(numstring);
  237.     if (try < bottom)  printf("Sorry, must be at least %d\n", bottom);
  238.     if (try > top   )  printf("Sorry, must be no more than %d\n", top);
  239.  
  240.     }
  241.   while (try < bottom ||  try > top);
  242.   return (int)try;
  243.  
  244.   }
  245. /*
  246. * getUtilString()
  247. *
  248. * This function gets a string from the user.
  249. */
  250. void getUtilString(prompt, buf, lim)
  251. char *prompt;
  252. char *buf;
  253. int  lim;       /* max # chars to read */
  254.   {
  255.   char *c;
  256.   short x;
  257.   printf("Enter %s:", prompt, lim);
  258.   c = fgets(buf,lim,stdin);
  259.   for(x=0; x<lim;x++)if( buf[x] == '\n')buf[x] = '\0';
  260.   printf("\n");
  261.  
  262.   }
  263. /*
  264. * logSort()
  265. *
  266. * This is used for sorting the log.
  267. */
  268. int logSort(s1, s2)
  269. LogTable *s1, *s2;
  270.   {
  271.   if (s1->ltnmhash == 0 && s2->ltnmhash == 0)
  272.   return 0;
  273.   if (s1->ltnmhash == 0 && s2->ltnmhash != 0)
  274.   return 1;
  275.   if (s1->ltnmhash != 0 && s2->ltnmhash == 0)
  276.   return -1;
  277.   if (s1->ltnewest < s2->ltnewest)
  278.   return 1;
  279.   if (s1->ltnewest > s2->ltnewest)
  280.   return -1;
  281.   return 0;
  282.  
  283.   }
  284. /*
  285. * logSum()
  286. *
  287. * This goes through the log to correct logTab.
  288. */
  289. void logSum()
  290.   {
  291.   int i;
  292.   int logSort();
  293.   int count = 0;
  294.   #ifdef WORKS
  295.   if (rewind(logfl) != 0) crashout("Rewinding logfl failed!");
  296.   #else
  297.   rewind(logfl);
  298.   #endif
  299.   /* clear logTab */
  300.   for (i = 0;i < cfg.MAXLOGTAB;i++) logTab[i].ltnewest = 0l;
  301.   /* load logTab: */
  302.   for (thisLog = 0;thisLog < cfg.MAXLOGTAB;thisLog++)
  303.     {
  304.     getLog(&logBuf, thisLog);
  305.     /* count valid entries:     */
  306.     if (logBuf.lbflags.L_INUSE)
  307.       {
  308.       if (strLen(logBuf.lbname) >= NAMESIZE ||
  309.       strLen(logBuf.lbpw) >= NAMESIZE )
  310.         {
  311.         logBuf.lbflags.L_INUSE = FALSE;
  312.         putLog(&logBuf, thisLog);
  313.  
  314.         }
  315.       else
  316.         {
  317.         count++;
  318.  
  319.         }
  320.  
  321.       };
  322.     /* copy relevant info into index:   */
  323.     logTab[thisLog].ltnewest = logBuf.lbvisit[0];
  324.     logTab[thisLog].ltlogSlot= thisLog;
  325.     if (logBuf.lbflags.L_INUSE == 1)
  326.       {
  327.       logTab[thisLog].ltnmhash = hash(logBuf.lbname);
  328.       logTab[thisLog].ltpwhash = hash(logBuf.lbpw  );
  329.       logTab[thisLog].ltpermanent = logBuf.lbflags.PERMANENT;
  330.  
  331.       }
  332.     else
  333.       {
  334.       logTab[thisLog].ltnmhash = 0;
  335.       logTab[thisLog].ltpwhash = 0;
  336.  
  337.       }
  338.  
  339.     }
  340.   printf(" logInit--%d valid log entries\n", count);
  341.   qsort((char *)logTab, cfg.MAXLOGTAB, cfg.sizeLTentry, logSort);
  342.  
  343.   }
  344. /*
  345. * main()
  346. *
  347. * Main controller.
  348. */
  349. main(argc, argv)
  350. int argc;
  351. char **argv;
  352.   {
  353.   SYS_FILE logfile;
  354.   printf("LOGEDIT V3.42\n%s\n", COPYRIGHT);
  355.   cfg.weAre = UTILITY;
  356.   if (!readSysTab(FALSE, TRUE)) exit(1);
  357.   if (access(LOCKFILE, 0) != -1)
  358.     {
  359.     printf("Please do not run LogEdit from Outside Commands.\n");
  360.     writeSysTab();
  361.     exit(1);
  362.  
  363.     }
  364.   makeSysName(logfile, "ctdllog.sys", &cfg.logArea);
  365.   openFile(logfile, &logfl);
  366.   initLogBuf(&logBuf);
  367.   makeSysName(logfile, "ctdlfwd.sys", &cfg.roomArea);
  368.   MakeList(&MailForward, logfile, NULL);
  369.   handleEditing();
  370.   logSum();
  371.   writeSysTab();
  372.   return 0;
  373.   }
  374. void showlog()
  375.   {
  376.   char *LastOn(long lastdate, char s);
  377.   printf(" %-20s",logBuf.lbname);
  378.   printf("%8ld", logBuf.lbvisit[0]);
  379.   printf(" %d columns. Date:%s\n",logBuf.lbwidth,LastOn(logBuf.lblaston, TRUE));
  380.   Display_Flag(0,logBuf.lbflags.AIDE       ,"AIDE Status        ");
  381.   Display_Flag(1,logBuf.lbflags.EXPERT     ,"Expert User        ");
  382.   Display_Flag(0,logBuf.lbflags.NET_PRIVS  ,"Network Privileges ");
  383.   Display_Flag(1,logBuf.lbflags.DOOR_PRIVS ,"Door Privileges    ");
  384.   Display_Flag(0,logBuf.lbflags.DL_PRIVS   ,"Download Privileges");
  385.   Display_Flag(1,logBuf.lbflags.PERMANENT  ,"Permanent Account  ");
  386.   Display_Flag(0,logBuf.lbflags.FLOORS     ,"Floor mode         ");
  387.   Display_Flag(1,logBuf.lbflags.TWIT       ,"TWIT User          ");
  388.   Display_Flag(0,logBuf.lbflags.RUGGIE     ,"RUGGIE User        ");
  389.   Display_Flag(1,logBuf.lbflags.L_INUSE    ,"Active Account     ");
  390.   Display_Flag(0,logBuf.lbflags.LFMASK     ,"LF FLAG            ");
  391.   Display_Flag(1,logBuf.lbflags.OLDTOO     ,"OLD STYLE          ");
  392.   Display_Flag(0,logBuf.lbflags.HALF_DUP   ,"HALF DUPLEX        ");
  393.   Display_Flag(1,logBuf.lbflags.ALT_RE     ,"ALT. Read Messages ");
  394.   Display_Flag(0,logBuf.lbflags.NoPrompt   ,"Room Name Prompt   ");
  395.   printf("\n");
  396.   }
  397. void Display_Flag(flag,bit,text)
  398. short  flag, bit;
  399. char  *text;
  400.   {
  401.   printf(" %s: %s%c",text,(bit ? "Yes" : "No "), (flag==0 ? '\t':'\n'));
  402.  
  403.   }
  404.